﻿/*
COPYRIGHT (C) 2009 EPISERVER AB

THIS FILE IS PART OF VIRTUAL ROLES SAMPLE PACK FOR EPISERVER CMS.
DYNAMIC CONTENT CONTRIB FOR EPISERVER CMS IS FREE SOFTWARE: YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE VERSION v2.1 AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.

VIRTUAL ROLES SAMPLE PACK FOR EPISERVER CMS IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE ALONG WITH VIRTUAL ROLES SAMPLE PACK FOR EPISERVER CMS. IF NOT, SEE <HTTP://WWW.GNU.ORG/LICENSES/>.
*/
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EPiServer.DynamicContent;
using EPiServer.SpecializedProperties;
using EPiServer.Core;
using EPiServer.Research.DynamicContent;
using EPiServer.Editor;

namespace EPiServer.Research.RoleBasedContent
{
    [DCPlugin(DisplayName="Role Based Content", Description="Content only intended for certain roles.")]
    public class RoleDynamicContent : DynamicContentBase, IDynamicContent
    {
        protected RoleSelector Roles;
        protected PropertyXhtmlString Text;

        public RoleDynamicContent()
        {
            Roles = new RoleSelector();
            Roles.Name = "Roles";
            Text = new PropertyXhtmlString();
            Text.Name = "Text";
            //if possible, set xhtml properties to those of the hosting parent.
            Text.EditorToolOptions = EditorToolOption.All;
        }

        #region IDynamicContent Members

        public override Control GetControl(EPiServer.PageBase hostPage)
        {
            if (!Roles.IsInRoles()) return new LiteralControl(string.Empty);
            EPiServer.Web.WebControls.Property p = new EPiServer.Web.WebControls.Property();
            p.InnerProperty = Text;
            return p;
        }

        public override EPiServer.Core.PropertyDataCollection Properties
        {
            get {
                PropertyDataCollection pdc = new PropertyDataCollection();
                pdc.Add(Roles);
                pdc.Add(Text);
                return pdc;
            }
        }

        public override string Render(EPiServer.PageBase hostPage)
        {
            throw (new NotImplementedException());
        }

        public override bool RendersWithControl
        {
            get { return true; }
        }


        #endregion
    }
}
